<template>
    <div class="dashboard-container">
        <el-button type="primary" size="small" icon="el-icon-arrow-left" @click="$router.back(-1)">返回</el-button>
        <el-card style="margin-top: 10px; width: 30%; min-width: 500px;">
            <table class="kv-table" v-loading="loading">
                <tr>
                    <td class="kv-label">
                        版本号
                    </td>
                    <td class="kv-content">
                        {{versionData.version}}
                    </td>
                </tr>
                <tr>
                    <td class="kv-label">
                        更新提示语
                    </td>
                    <td class="kv-content">
                        {{versionData.notice}}
                    </td>
                </tr>
                <tr>
                    <td class="kv-label">
                        更新方式
                    </td>
                    <td class="kv-content">
                        {{updateKv[versionData.type] || '-'}}
                    </td>
                </tr>
                <tr>
                    <td class="kv-label">
                        操作系统
                    </td>
                    <td class="kv-content">
                        {{versionData.system}}
                    </td>
                </tr>
                <tr>
                    <td class="kv-label">
                        下载地址
                    </td>
                    <td class="kv-content">
                        {{versionData.download}}
                    </td>
                </tr>
            </table>
        </el-card>
    </div>
</template>

<script>
  import { UPDATE_KV } from '@/utils/constant'
  import { getInfo } from '@/api/version'

  export default {
    name: 'detail',
    data() {
      return {
        versionData: {
          'version': '1.0.2',//... <string>
          'type': 10,//... <number>
          'notice': '新版本上线啦',//... <string>
          'system': 'IOS',//... <string>
          'download': 'http://aliyun.downliad.com/xxx.apk'//... <string>
        },
        updateKv: UPDATE_KV,
        id: '',
        loading: false
      }
    },
    methods: {
      async getInfo () {
        try {
          this.loading = true
          const res = await getInfo({
            id: this.id
          })
          this.versionData = res.data
          this.loading = false
        } catch (e) {
          console.log(e)
          this.loading = false
        }
      }
    },
    mounted() {
      if (this.$route.query.id) {
        this.id = this.$route.query.id
        this.getInfo()
      } else {
        this.$message.warning('没有获取到userId')
        this.$router.push('/systemManage')
      }
    }
  }
</script>

<style scoped>

</style>
